//
//  SmsCloudMainVipView.m
#import "SmsCloudMainVipView.h"
@interface SmsCloudMainVipView()
@property (nonatomic,strong) UILabel *smsCloudMainVipNameLab;
@property (nonatomic,strong) UILabel *smsCloudMainVipTitleLab;
@property (nonatomic,strong) UIButton *smsCloudMainOpenVipBtn;
@end
@implementation SmsCloudMainVipView
-(instancetype)init{
    if (self == [super init]) {
        [self smsCloudInitView];
    }
    return self;
}
- (void)smsCloudInitView{
    UIImageView * smsCloudMainVipImgBgView = [[UIImageView alloc] init];
    smsCloudMainVipImgBgView.userInteractionEnabled = true;
    smsCloudMainVipImgBgView.image = [SmsCloudHead SmsCloudImageNamed:@"smsCloudVipHeadBg"];
    [self addSubview:smsCloudMainVipImgBgView];
    [smsCloudMainVipImgBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:24]));
        make.right.equalTo(@(-[SmsCloudHead SmsCloudScreewRatio:24]));
        make.top.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:220]));
    }];
    self.smsCloudMainVipNameLab = [[UILabel alloc] init];
    self.smsCloudMainVipNameLab.textColor = [SmsCloudHead SmsCloudColorHexString:@"#562D0B"];
    self.smsCloudMainVipNameLab.font = [UIFont systemFontOfSize:[SmsCloudHead SmsCloudScreewRatio:38] weight:UIFontWeightRegular];
    [smsCloudMainVipImgBgView addSubview:self.smsCloudMainVipNameLab];
    [self.smsCloudMainVipNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:31]));
        make.top.equalTo(@([SmsCloudHead SmsCloudScreewRatio:51]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:50]));
    }];
    self.smsCloudMainVipTitleLab = [[UILabel alloc] init];
    self.smsCloudMainVipTitleLab.textColor = [SmsCloudHead SmsCloudColorHexString:@"#562D0B"];
    self.smsCloudMainVipTitleLab.font = [UIFont systemFontOfSize:[SmsCloudHead SmsCloudScreewRatio:24] weight:UIFontWeightRegular];
    [smsCloudMainVipImgBgView addSubview:self.smsCloudMainVipTitleLab];
    [self.smsCloudMainVipTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:31]));
        make.top.equalTo(self.smsCloudMainVipNameLab.mas_bottom).offset([SmsCloudHead SmsCloudScreewRatio:14]);
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:34]));
    }];
    self.smsCloudMainOpenVipBtn = [[UIButton alloc] init];
    [self.smsCloudMainOpenVipBtn setBackgroundImage:[SmsCloudHead SmsCloudImageNamed:@"smsCloudOpenVip"] forState:UIControlStateNormal];
    [self.smsCloudMainOpenVipBtn addTarget:self action:@selector(smsCloudMainOpenVip) forControlEvents:UIControlEventTouchUpInside];
    [smsCloudMainVipImgBgView addSubview:self.smsCloudMainOpenVipBtn];
    [self.smsCloudMainOpenVipBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-[SmsCloudHead SmsCloudScreewRatio:47]));
        make.centerY.equalTo(smsCloudMainVipImgBgView);
        make.width.equalTo(@([SmsCloudHead SmsCloudScreewRatio:180]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:62]));
    }];
    [self smsCloudUpdataVip];
}
- (void)smsCloudMainOpenVip{
    if(self.SmsCloudMainOpenVipBlock){
        self.SmsCloudMainOpenVipBlock();
    }
}
- (void)smsCloudUpdataVip{
    if ([SmsCloudHead isSmsCloudVip]) {
        self.smsCloudMainVipNameLab.text = @"你已是会员";
        self.smsCloudMainOpenVipBtn.hidden = true;
        
        NSTimeInterval smsCloudVipBuyTime = (NSTimeInterval)[[NSUserDefaults standardUserDefaults] doubleForKey:@"smsCloudVipBuyTime"];
        NSDate *smsCloudVipBuyTimeDate = [NSDate dateWithTimeIntervalSince1970:smsCloudVipBuyTime];
        NSDateFormatter *smsCloudVipBuyTimeDateDateFormat = [[NSDateFormatter alloc] init];
        [smsCloudVipBuyTimeDateDateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // 设置日期格式
        // 格式化日期并输出
        NSString *smsCloudVipBuyTimeCurTime = [smsCloudVipBuyTimeDateDateFormat stringFromDate:smsCloudVipBuyTimeDate];
        self.smsCloudMainVipTitleLab.text = [NSString stringWithFormat:@"会员有效期至:%@",smsCloudVipBuyTimeCurTime];
    }else{
        self.smsCloudMainVipNameLab.text = @"开通会员";
        self.smsCloudMainVipTitleLab.text = @"享受所有会员权益  体验翻倍";
        self.smsCloudMainOpenVipBtn.hidden = false;
    }
}
@end
